//
//  getCommonDataMode.m
//  XYMaterial
//
//  Created by 肖扬 on 15/12/15.
//  Copyright © 2015年 肖扬. All rights reserved.
//

#import "getCommonDataMode.h"

@implementation getCommonDataMode
@synthesize data;
-(id)init{
    self = [super init];
    if (self) {
        self.data = [NSMutableDictionary dictionary];
    }
    return self;
}
-(void)parseResponseData:(NSString *)responseString{
    [super parseResponseData:responseString];
    NSDictionary *dic           = [responseString objectFromJSONString];
    NSDictionary *tempData          = [NSDictionary dictionary];
    tempData = [dic objectForKey:@"data"];
    NSMutableArray *tempA1 = [NSMutableArray array];
    NSMutableArray *tempA2 = [NSMutableArray array];
    NSMutableArray *tempA3 = [NSMutableArray array];
    NSMutableArray *tempA4 = [NSMutableArray array];
    NSArray *eplevelsArr = [tempData objectForKey:@"eplevels"];
    for (int i = 0; i <[eplevelsArr count]; i++) {
        eplevelsModel *model = [[eplevelsModel alloc]init];
        model.name = [eplevelsArr objectAtIndex:i];
        [tempA1 addObject:model];
    }
    NSArray *texturesArr = [tempData objectForKey:@"textures"];
    for (int i = 0; i <[texturesArr count]; i++) {
        texturesModel *model = [[texturesModel alloc]init];
        model.name = [texturesArr objectAtIndex:i];
        [tempA2 addObject:model];
    }
    NSArray *stuffsArr = [tempData objectForKey:@"stuffs"];
    for (int i = 0; i <[stuffsArr count]; i++) {
        stuffsModel *model = [[stuffsModel alloc]init];
        model.name = [stuffsArr objectAtIndex:i];
        [tempA3 addObject:model];
    }
    NSArray *gramsArr = [tempData objectForKey:@"grams"];
    for (int i = 0; i <[gramsArr count]; i++) {
        gramsModel *model = [[gramsModel alloc]init];
        model.name = [gramsArr objectAtIndex:i];
        [tempA4 addObject:model];
    }
    [self.data setObject:tempA1 forKey:@"eplevels"];
    [self.data setObject:tempA2 forKey:@"textures"];
    [self.data setObject:tempA3 forKey:@"stuffs"];
    [self.data setObject:tempA4 forKey:@"grams"];
    NSDictionary *tempMaterials = [NSDictionary dictionary];
    tempMaterials = [tempData objectForKey:@"materials"];
    NSMutableDictionary *materD = [NSMutableDictionary dictionary];
    NSMutableDictionary *brandD = [NSMutableDictionary dictionary];
    for (int i = 0; i <[tempMaterials count]; i++) {
        NSArray *tempArr = [tempMaterials objectForKey:[[tempMaterials allKeys] objectAtIndex:i]];
        materialsModel *model   = [[materialsModel alloc]init];
        model.materialsName     = [[tempMaterials allKeys]objectAtIndex:i];
        for (int k = 0; k <[tempArr count]; k++) {
            NSDictionary *tempModel = [tempArr objectAtIndex:k];
            plankModel *plank       = [[plankModel alloc]init];
            plank.material_id       = [tempModel objectForKey:@"material_id"];
            plank.name              = [tempModel objectForKey:@"name"];
            plank.level             = [tempModel objectForKey:@"level"];
            plank.parent            = [tempModel objectForKey:@"parent"];
            plank.brand             = [tempModel objectForKey:@"brand"];
            plank.is_delete         = [tempModel objectForKey:@"is_delete"];
            [model.materialsData addObject:plank];
        }
        [materD setObject:model.materialsData forKey:model.materialsName];
    }
    [self.data setObject:materD forKey:@"materials"];
    NSDictionary *brandsTempDic = [tempData objectForKey:@"brands"];
    for (int i = 0; i <[brandsTempDic count]; i++) {
        NSArray *tempArr = [brandsTempDic objectForKey:[[brandsTempDic allKeys] objectAtIndex:i]];
        brandsModel *model   = [[brandsModel alloc]init];
        model.brandsNo     = [[brandsTempDic allKeys]objectAtIndex:i];
        for (int k = 0; k <[tempArr count]; k++) {
            NSDictionary *tempModel = [tempArr objectAtIndex:k];
            tj_brandsModel *brands  = [[tj_brandsModel alloc]init];
            brands.brand_id         = [tempModel objectForKey:@"brand_id"];
            brands.name             = [tempModel objectForKey:@"name"];
            brands.intro            = [tempModel objectForKey:@"intro"];
            brands.logo             = [tempModel objectForKey:@"logo"];
            brands.producer_id      = [tempModel objectForKey:@"producer_id"];
            brands.pinyin           = [tempModel objectForKey:@"pinyin"];
            brands.displayorder     = [tempModel objectForKey:@"displayorder"];
            brands.is_delete        = [tempModel objectForKey:@"is_delete"];
            [model.brandsData addObject:brands];
        }
        [brandD setObject:model.brandsData forKey:model.brandsNo];
    }
    [self.data setObject:brandD forKey:@"brands"];
    NSArray      *tj_brandsTemp = [tempData objectForKey:@"tj_brands"];
    brandsModel *model   = [[brandsModel alloc]init];
    model.brandsNo     = @"tj_brands";
    for (int k = 0; k <[tj_brandsTemp count]; k++) {
        NSDictionary *tempModel = [tj_brandsTemp objectAtIndex:k];
        tj_brandsModel *brands  = [[tj_brandsModel alloc]init];
        brands.brand_id         = [tempModel objectForKey:@"brand_id"];
        brands.name             = [tempModel objectForKey:@"name"];
        brands.intro            = [tempModel objectForKey:@"intro"];
        brands.logo             = [tempModel objectForKey:@"logo"];
        brands.producer_id      = [tempModel objectForKey:@"producer_id"];
        brands.pinyin           = [tempModel objectForKey:@"pinyin"];
        brands.displayorder     = [tempModel objectForKey:@"displayorder"];
        brands.is_delete        = [tempModel objectForKey:@"is_delete"];
        [model.brandsData addObject:brands];
    }
    [self.data setObject:model.brandsData forKey:@"tj_brands"];
}
-(void)dealloc{
    self.data = nil;
}
@end

@implementation materialsModel

@synthesize materialsName,materialsData;
-(id)init{
    self = [super init];
    if (self) {
        self.materialsData = [NSMutableArray array];
    }
    return self;
}
-(void)dealloc{
//    [self.materialsData removeAllObjects];
    self.materialsData = nil;
}
@end

@implementation plankModel

@synthesize material_id,name,level,parent,brand,is_delete;

@end

@implementation brandsModel

@synthesize brandsData,brandsNo;
-(id)init{
    self = [super init];
    if (self) {
        self.brandsData = [NSMutableArray array];
    }
    return self;
}
-(void)dealloc{
//    [self.brandsData removeAllObjects];
    self.brandsData = nil;
}
@end

@implementation tj_brandsModel

@synthesize brand_id,name,intro,logo,producer,producer_id,pinyin,displayorder,is_delete;

@end

@implementation eplevelsModel

@synthesize name;

@end

@implementation texturesModel

@synthesize name;

@end

@implementation stuffsModel

@synthesize name;

@end

@implementation gramsModel

@synthesize name;

@end
